package com.huawang.mdesign.model.service.util;

import com.huawang.business.dto.PropertyConfig;

import java.util.List;

public class ModelInstanceUtil {

    private ModelInstanceUtil() {
    }

    /**
     * 属性信息按照指定名称排序
     *
     * @param orderList
     * @param propertyConfigInfos
     * @return void
     * @author xz
     * @date 2024/03/22 16:30
     */
    public static void diagramTableSortByColumn(List<String> orderList, List<? extends PropertyConfig> propertyConfigInfos) {
        propertyConfigInfos.sort(((o1, o2) -> {
            if (orderList.contains(o1.getKey()) && orderList.contains(o2.getKey())) {
                return Integer.compare(orderList.indexOf(o1.getKey()),
                        orderList.indexOf(o2.getKey()));
            } else if (orderList.contains(o1.getKey()) && !orderList.contains(o2.getKey())) {
                return -1;
            } else if (!orderList.contains(o1.getKey()) && orderList.contains(o2.getKey())) {
                return 1;
            } else {
                return 0;
            }
        }));
    }
}
